﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using COMOSOFT.Class;

namespace COMOSOFT.OrderBusiness.Forms
{
    public partial class FrmApprovingManagement : Form
    {
        FrmFactoryPurchaseMaster frFPM = null;
        ClassShare cls = new ClassShare("FrmApprovingManagement");
        string FPMIDs = null;
        string OIDs = null;
        public FrmApprovingManagement()
        {
            InitializeComponent();
        }

        private void FrmApprovingManagement_Load(object sender, EventArgs e)
        {           
            this.employeeTableAdapter.Fill(this.dataSetOrderManagement.Employee);
            LoadData();
        }
        #region [Load Data]
        public void LoadData()
        {
            if (radio.SelectedIndex == 0)
            {
                sp_ApprovingManagementTableAdapter.Fill(dataSetOrderManagement.sp_ApprovingManagement, ClassShare.Usid, 0);
            }
            else
                sp_ApprovingManagementTableAdapter.Fill(dataSetOrderManagement.sp_ApprovingManagement, ClassShare.Usid, 1);
        }
        #endregion
        private void radio_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoadData();
        }
        #region [Double Click Griview]
        private void gridView_ApproPur_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                int fpid = Convert.ToInt32(gridView_ApproPur.GetFocusedDataRow()["FPMID"]);               
                ClassShare.fpid = fpid;                
                frFPM = new FrmFactoryPurchaseMaster(fpid);               
                frFPM.Text ="PO: "+ gridView_ApproPur.GetFocusedDataRow()["PONo"].ToString();
                frFPM.LoadFPM();
                frFPM.StatusButton("Approval");
                frFPM.Show();               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        #endregion
        private void toolStripTxt_comment_Click(object sender, EventArgs e)
        {
            toolStripTxt_comment.Text = "";
        }
        #region [CallReport]
        private void CallReport()
        {
            try
            {
                int flag = 0;
                FPMIDs = null;
                OIDs = null;
                int[] numrow = gridView_ApproPur.GetSelectedRows();
                foreach (int i in numrow)
                {
                    if (flag == 0)
                    {
                        FPMIDs = gridView_ApproPur.GetDataRow(i)["FPMID"].ToString();
                        OIDs = gridView_ApproPur.GetDataRow(i)["OID"].ToString();
                        flag = 1;
                    }
                    else
                    {
                        FPMIDs += "," + gridView_ApproPur.GetDataRow(i)["FPMID"].ToString();
                        OIDs += "," + gridView_ApproPur.GetDataRow(i)["OID"].ToString();
                    }
                }                
                ClassShare.FPMIDs = FPMIDs;
                ClassShare.OIDs = OIDs;               
                FrmReport frmrpt = new FrmReport("rptFtyPurMaster");
                frmrpt.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        #endregion
        #region[Rejects]
        private void oKToolStripMenuItem_Click(object sender, EventArgs e)
        {
            toolStripTxt_comment.Text = "Please give comment...";
            CallReport();
            cls.UpdateData("sp_FtyPurMasterUpdateStatus", new string[3] { "@FPMIDs", "@comment", "@flag" }, new object[3] { FPMIDs, toolStripTxt_comment.Text, 2 });
            LoadData();
        }
        #endregion
        #region [Approval]
        private void approvalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CallReport();
            cls.UpdateData("sp_FtyPurMasterUpdateStatus", new string[3] { "@FPMIDs","@comment","@flag" }, new object[3] { FPMIDs,"",1 });
        }
        #endregion
    }
}
